"""
公共fixture
"""
import pytest
from common.commonfunc import CommonLog, get_config, read_data_by_yaml,get_data_by_dict

config = get_config()
start_log = CommonLog(__name__, log_path=config['LogPath'])


def pytest_collection_modifyitems(items):
    """
    测试用例收集完成时，将收集到的item的name和nodeid的中文显示在控制台上
    :return:
    """
    for item in items:
        item.name = item.name.encode("utf-8").decode("unicode_escape")
        item._nodeid = item.nodeid.encode("utf-8").decode("unicode_escape")


# 使用fixture 实现setup/teardown 功能

@pytest.fixture(scope='session', autouse=True)
def start_test():
    """
       日志上输出【开始测试】
       :return:
       """
    start_log.log_info('\n【开始测试】\n')


@pytest.fixture(scope='session', autouse=True)
def finish_test():
    """
       日志上输出【结束测试】
       :return:
       """
    yield
    start_log.log_info('\n【结束测试】\n')


@pytest.fixture(scope='session',autouse=True)
def get_test_data_path():
    """
         返回TestData文件路径
         :return:
         """
    return dict(get_data_by_dict(config['TestData']))


@pytest.fixture(scope='session',autouse=True)
def get_log_path():
    """
         返回日志文件路径
         :return:
         """
    return config['LogPath']


@pytest.fixture(scope='session',autouse=True)
def get_report_path():
    """
         返回报告路径
         :return:
         """
    return config['ReportPath']


@pytest.fixture(scope='session',autouse=True)
def get_api_path():
    """
         返回接口数据路径
         :return:
         """
    return config['ApiPath']

@pytest.fixture(scope='session',autouse=True)
def get_test_env():
    """
         返回环境配置路径
         :return:
         """
    return config['Env']